package com.lili.other;

import java.util.LinkedList;

/**
 * @Auther: 李 力
 * @Date: 2024/8/24
 * @Description: 155.最小栈
 * @version: 1.0
 */
public class MinStack {
    //原始栈
    LinkedList<Integer> stack = new LinkedList<>();
    //记录最小值的栈
    LinkedList<Integer> min = new LinkedList<>();


    public MinStack() {
        min.push(Integer.MAX_VALUE);
    }

    public void push(int val) {
        stack.push(val);
        int item = Math.min(val, min.peek());
        min.push(item);
    }

    public void pop() {
        if (stack.isEmpty()) {
            return;
        }
        stack.pop();
        min.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }
}
